home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 94 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.7 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: jbuck@Synopsys.COM (Joe Buck)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: STL experts, please comment
  5. Date: 22 Jan 1996 13:52:26 PST
  6. Organization: Synopsys Inc., Mountain View, CA 94043-4033
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4e1034$5ar@hermes.synopsys.com>
  9. References: <4dnteb$6fo@news.bridge.net>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 22 Jan 1996 21:37:40 GMT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMQQHK0y4NqrwXLNJAQH1RwH+PorMyPbKxU1d95lrC1weXzY6i6mKneIq
  14.     JoEGbksEgXkpU/cyPXdES56N0XCCz4JPmX4P1B7FGCqNUUJMH+aojw==
  15.     =9iaz
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. David Byrden <100101.2547@compuserve.com> writes:
  19. >In the HP STL, deque::iterator has a default ctor which initialises
  20. >several of its members with the value 0
  21. >
  22. >    iterator() : current(0), first(0), last(0), node(0) {}
  23.  
  24. Checking the code, this initialization to 0 is evidently not used
  25. anywhere.  However, if the members are not initialized at all, tools
  26. like Purify may complain about uninitialized memory reads.  Perhaps
  27. this is why it's there.  The problem is the "default constructor"
  28. for pointers doesn't do anything; it leaves the pointer with a random
  29. value.
  30.  
  31. Almost seems like what you'd really want for STL is a template for
  32. initializing iterators that would be specialized for pointers; pointers
  33. would be initialized to zero; other class types would just get initialized
  34. by their default constructor (this would need partial specialization, I
  35. think).  But that would in effect create an implicit NIL for all iterators
  36. (well, we could always argue about that question again).  But maybe a NIL
  37. is only needed for allocator pointers and not iterators in general.
  38.  
  39. >These members have the type deque::pointer, which is a typedef
  40. >for the pointer in deque's allocator.
  41. >An allocator pointer, according to the standard, has exactly the same
  42. >semantics as a random access iterator.
  43.  
  44. So you're trying to create an allocator that is not based on pointers.
  45.  
  46. >I can find no place where it says that all random access iterators 
  47. >should be constructable from the int value zero, neither in 
  48. >documentation from the time of the HP STL, nor the latest draft standard.
  49.  
  50. Correct.
  51.  
  52. >So, this ctor seems to break the rules. Yet it was written by the 
  53. >inventors of STL.
  54.  
  55. Well, they goofed, I suppose.  Seems the types of allocators they used
  56. were all pointers, so they didn't test out other cases.
  57.  
  58.  
  59. -- 
  60. -- Joe Buck     <jbuck@synopsys.com>    (not speaking for Synopsys, Inc)
  61. ---
  62. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  63.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  64.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  65.